home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / Rxil.lha / Rxil / src / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-30  |  5.0 KB  |  304 lines

  1. /* misc.c */
  2.  
  3. /*        Copyright © 1989 by Donald T. Meyer, Stormgate Software
  4.  *        All Rights Reserved
  5.  */
  6.  
  7.  
  8.  
  9. #include "rxil.h"
  10.  
  11.  
  12.  
  13. /* NAME
  14.  *        RxilGetReturn
  15.  *
  16.  * SYNOPSIS
  17.  *        rxi = RxilGetReturn();
  18.  *
  19.  *        struct RxilInvocation *rxi;
  20.  *
  21.  * FUNCTION
  22.  *        This will return a pointer to any RxilInvocation message
  23.  *        that has been replyed (but not yet cleaned up and available).
  24.  *        NULL will be returned if all RxilInvocation structures which have
  25.  *        been allocated are available or pending.
  26.  *
  27.  * INPUTS
  28.  *        None
  29.  *
  30.  * RESULT
  31.  *        A pointer to a RxilInvocation structure.  If none have been
  32.  *        replied and are available to be handled, this will return a NULL.
  33.  *
  34.  * SIDES
  35.  *
  36.  * HISTORY
  37.  *        01-Aug-89    Creation.
  38.  *
  39.  * BUGS
  40.  *
  41.  * SEE ALSO
  42.  *
  43.  */
  44.  
  45. struct RxilInvocation *RxilGetReturn( void )
  46. {
  47.     struct RxilInvocation *rxi;
  48.  
  49.  
  50.     /* Make call "safe" even if RxilInit() failed */
  51.     if( global_rdef == NULL )
  52.     {
  53.         return( NULL );
  54.     }
  55.  
  56.  
  57.     for( rxi=global_rdef->Invocations; rxi; rxi=rxi->Next )
  58.     {
  59.         if( rxi->State == RXIL_STATE_RETURNED )
  60.         {
  61.             return( rxi );
  62.         }
  63.     }
  64.  
  65.     return( NULL );
  66. }
  67.  
  68.  
  69.  
  70. /* NAME
  71.  *        RxilCleanupReturn
  72.  *
  73.  * SYNOPSIS
  74.  *        RxilCleanupReturn( rxi );
  75.  *
  76.  *        struct RxilInvovcation *rxi;
  77.  *
  78.  * FUNCTION
  79.  *         This will take a pointer to a RxilInvocation structure and
  80.  *        free what needs to be freed.
  81.  *        The RexxMsg pointer is then NULL'ed and the structure's state
  82.  *        set to AVAILABLE.
  83.  *
  84.  *        This should be called by the main program to cleanup after
  85.  *        a function or command has returned and after the main program
  86.  *        has done whatever it wanted to with the result.
  87.  *        This will close the extension filehandles for Stdin and Stdout.
  88.  *
  89.  * INPUTS
  90.  *        rxi = pointer to the RxilInvocation structure to be cleaned up.
  91.  *
  92.  * RESULT
  93.  *        None
  94.  *
  95.  * SIDES
  96.  *
  97.  * HISTORY
  98.  *        01-Aug-89    Creation.
  99.  *
  100.  * BUGS
  101.  *
  102.  * SEE ALSO
  103.  *        RxilCreateRxi(), RxilDeleteRxi(), RxilGetReturn()
  104.  */
  105.  
  106. void RxilCleanupReturn( struct RxilInvocation *rxi )
  107. {
  108.     struct RexxMsg *rexxmsg = rxi->RexxMsg;
  109.     int i;
  110.  
  111.  
  112.     RxilCloseConsole( rexxmsg );
  113.  
  114.     if(  ( rexxmsg->rm_Result1 == 0 ) && ( rexxmsg->rm_Result2 != 0 )  )
  115.     {
  116.          /* Free up the result string */
  117.         DeleteArgstring( (struct RexxArg *)rexxmsg->rm_Result2 );
  118.     }
  119.  
  120.  
  121.     /* We always delete the name string argument */
  122.     DeleteArgstring( (struct RexxArg *)(ARG0(rexxmsg)) );
  123.  
  124.     /* If a function invocation, free up any and all arguments */
  125.     if(  ( rexxmsg->rm_Action & RXCODEMASK ) == RXFUNC  )
  126.     {
  127.         for( i=1; i<=(rexxmsg->rm_Action & RXARGMASK); i++ )
  128.         {
  129.             if( rexxmsg->rm_Args[i] != NULL )
  130.             {
  131.                 DeleteArgstring( (struct RexxArg *)
  132.                     (rexxmsg->rm_Args[i]) );
  133.             }
  134.         }
  135.     }
  136.  
  137.     DeleteRexxMsg( rexxmsg );
  138.     rxi->RexxMsg = NULL;
  139.  
  140.     rxi->State = RXIL_STATE_AVAILABLE;
  141. }
  142.  
  143.  
  144.  
  145. /* NAME
  146.  *        RxilPending
  147.  *
  148.  * SYNOPSIS
  149.  *        flag = RxilPending();
  150.  *
  151.  * FUNCTION
  152.  *        If any ARexx functions or commands have been launched via
  153.  *        a call to RxilLaunch(), and have not yet terminated, this will
  154.  *        return TRUE.
  155.  *
  156.  * INPUTS
  157.  *        None
  158.  *
  159.  * RESULT
  160.  *        A boolean flag which indicates if any launches are in progress.
  161.  *
  162.  * SIDES
  163.  *
  164.  * HISTORY
  165.  *        01-Aug-89    Creation.
  166.  *
  167.  * BUGS
  168.  *
  169.  * SEE ALSO
  170.  *        RxilLaunch(), RxilCmdPending(), RxilFuncPending()
  171.  */
  172.  
  173. BOOL RxilPending( void )
  174. {
  175.     struct RxilInvocation *rxi;
  176.  
  177.  
  178.     /* Make call "safe" even if RxilInit() failed */
  179.     if( global_rdef == NULL )
  180.     {
  181.         return( FALSE );
  182.     }
  183.  
  184.  
  185.     for( rxi=global_rdef->Invocations; rxi; rxi=rxi->Next )
  186.     {
  187.         if( rxi->State == RXIL_STATE_PENDING )
  188.         {
  189.             return( TRUE );
  190.         }
  191.     }
  192.  
  193.     return( FALSE );
  194. }
  195.  
  196.  
  197.  
  198. /* NAME
  199.  *        RxilCmdPending
  200.  *
  201.  * SYNOPSIS
  202.  *        flag = RxilCmdPending();
  203.  *
  204.  * FUNCTION
  205.  *        If any ARexx commands have been launched via
  206.  *        a call to RxilLaunch(), and have not yet terminated, this will
  207.  *        return TRUE.
  208.  *
  209.  * INPUTS
  210.  *        None
  211.  *
  212.  * RESULT
  213.  *        A boolean flag which indicates if any launches are in progress.
  214.  *
  215.  * SIDES
  216.  *
  217.  * HISTORY
  218.  *        01-Aug-89    Creation.
  219.  *
  220.  * BUGS
  221.  *
  222.  * SEE ALSO
  223.  *        RxilLaunch(), RxilPending(), RxilFuncPending()
  224.  */
  225.  
  226. BOOL RxilCmdPending( void )
  227. {
  228.     struct RxilInvocation *rxi;
  229.  
  230.  
  231.     /* Make call "safe" even if RxilInit() failed */
  232.     if( global_rdef == NULL )
  233.     {
  234.         return( FALSE );
  235.     }
  236.  
  237.  
  238.     for( rxi=global_rdef->Invocations; rxi; rxi=rxi->Next )
  239.     {
  240.         if(  ( rxi->State == RXIL_STATE_PENDING ) &&
  241.             ( rxi->Type == RXCOMM  )  )
  242.         {
  243.             return( TRUE );
  244.         }
  245.     }
  246.  
  247.     return( FALSE );
  248. }
  249.  
  250.  
  251.  
  252. /* NAME
  253.  *        RxilFuncPending
  254.  *
  255.  * SYNOPSIS
  256.  *        flag = RxilFuncPending();
  257.  *
  258.  * FUNCTION
  259.  *        If any ARexx functions have been launched via
  260.  *        a call to RxilLaunch(), and have not yet terminated, this will
  261.  *        return TRUE.
  262.  *
  263.  * INPUTS
  264.  *        None
  265.  *
  266.  * RESULT
  267.  *        A boolean flag which indicates if any launches are in progress.
  268.  *
  269.  * SIDES
  270.  *
  271.  * HISTORY
  272.  *        01-Aug-89    Creation.
  273.  *
  274.  * BUGS
  275.  *
  276.  * SEE ALSO
  277.  *        RxilLaunch(), RxilPending(), RxilCmdPending()
  278.  */
  279.  
  280. BOOL RxilFuncPending( void )
  281. {
  282.     struct RxilInvocation *rxi;
  283.  
  284.  
  285.     /* Make call "safe" even if RxilInit() failed */
  286.     if( global_rdef == NULL )
  287.     {
  288.         return( FALSE );
  289.     }
  290.  
  291.  
  292.     for( rxi=global_rdef->Invocations; rxi; rxi=rxi->Next )
  293.     {
  294.         if(  ( rxi->State == RXIL_STATE_PENDING ) &&
  295.             ( rxi->Type == RXFUNC  )  )
  296.         {
  297.             return( TRUE );
  298.         }
  299.     }
  300.  
  301.     return( FALSE );
  302. }
  303.  
  304.